import { WelfareItem } from "./WelfareItem";
import { Language } from "../../../../../extend/language/Language";
import { VIPConfig } from "../../../resource/VIPConfig";
import { Dispatcher } from "../../../../mvc/core/Dispatcher";
import { DataEvent } from "../../../events/DataEvent";
import { EventName } from "../../../mvc/EventName";
import { ClockManager } from "../../../manager/ClockManager";
import { SVIPInfo } from "../../../../../Message/Game/SVIPInfo";
import { EVIPType } from "../../../../../Message/Public/EVIPType";
import { Cache } from "../../../cache/Cache";
import { ItemData } from "../../../resource/info/ItemData";
import { ColorConfig } from "../../../resource/ColorConfig";
import { GlobalStyle } from "../../../../common/global/GlobalStyle";
import { HTMLUtil } from "../../../../../com/gengine/utils/HTMLUtil";
import { GButton } from "../../../../../com/mui/controls/GButton";
import { FilterConst } from "../../../../component/gconst/FilterConst";
//class WelfareVIPItem
    
    export  class WelfareVIPItem extends WelfareItem
    {
        constructor()
        {
            super();
            this._goldTxt = new Object /* flash.text.TextField */();
            this._copperTxt = new Object /* flash.text.TextField */();
            this._blessTxt = new Object /* flash.text.TextField */();
            this._flyTxt = new Object /* flash.text.TextField */();
            this._textFields = [this._goldTxt, this._copperTxt, this._blessTxt, this._flyTxt];
            this._textStrs = ["1." + Language.getStringByParam(20580, 0) + "," + Language.getStringByParam(20581, 0), "2." + Language.getStringByParam(20582, 0), "3." + Language.getStringByParam(20583) + "：", "4." + Language.getStringByParam(20584, 0)];
            return;
        }

        /* internal  */onGetBtn1ClickHandler(arg1: Object /* flash.events.MouseEvent */): void
        {
            if (!(this._vipInfo.rewards & 1)) 
            {
                if (this._attriName && VIPConfig.instance.getVIPInfo("EVIPCodeLoginReward")[this._attriName] > 0) 
                {
                    Dispatcher.dispatchEvent(new DataEvent(EventName.GetVIPRewards, 0));
                }
            }
            if (!(this._vipInfo.rewards & 4)) 
            {
                if (this._attriName && VIPConfig.instance.getVIPInfo("EVIPCodeDrugChangeNum")[this._attriName] > 0) 
                {
                    Dispatcher.dispatchEvent(new DataEvent(EventName.GetVIPRewards, 2));
                }
            }
            return;
        }

        /* internal  */onGetBtn2ClickHandler(arg1: Object /* flash.events.MouseEvent */): void
        {
            if (!(this._vipInfo.rewards & 2)) 
            {
                if (ClockManager.instance.nowDate.day == 6 || ClockManager.instance.nowDate.day == 0) 
                {
                    if (this._attriName && VIPConfig.instance.getVIPInfo("EVIPCodeWeekendReward")[this._attriName] > 0) 
                    {
                        Dispatcher.dispatchEvent(new DataEvent(EventName.GetVIPRewards, 1));
                    }
                }
            }
            return;
        }

        /* internal  */onBlessGetBtnClickHandler(arg1: Object /* flash.events.MouseEvent */): void
        {
            Dispatcher.dispatchEvent(new DataEvent(EventName.GetVIPRewards, 4));
            return;
        }

        public updateVIPInfo(arg1: SVIPInfo): void
        {
            this._vipInfo = arg1;
            if (!this._vipInfo) 
            {
                return;
            }
            var loc1=this._vipInfo.VIPType.value();
            switch (loc1) 
            {
                case EVIPType._EVIPTypeNormal:
                {
                    this._attriName = null;
                    this.normalVip();
                    break;
                }
                case EVIPType._EVIPTypeWeek:
                {
                    this._attriName = "weekVal";
                    this.weekVip("weekVal");
                    break;
                }
                case EVIPType._EVIPTypeMonth:
                {
                    this._attriName = "monthVal";
                    this.monthVip("monthVal");
                    break;
                }
                case EVIPType._EVIPTypeHalfYear:
                {
                    this._attriName = "halfYearVal";
                    this.halfYearVip("halfYearVal");
                    break;
                }
            }
            this.updateRewardsState();
            return;
        }

        public updateBlessState(arg1: Boolean): void
        {
            this._isStart = arg1;
            if (!this._vipInfo) 
            {
                return;
            }
            return;
        }

        /* internal  */updateRewardsState(): void
        {
            return;
        }

        /* internal  */normalVip(): void
        {
            var loc2=0;
            var loc4=null;
            var loc5=null;
            var loc6=null;
            _titleTxt2.text = Language.getString(20587);
            var loc1=Cache.instance.vip.weekGiftItemCode;
            if (loc1 != 0) 
            {
                loc5 = new ItemData(loc1);
                loc6 = ColorConfig.instance.getItemColor(loc5.itemInfo.item.color).color;
                this._textStrs[2] = "3.<font color=\'" + loc6 + "\'>" + loc5.itemInfo.item.name + "</font>";
            }
            var loc3=this._textFields.length;
            while (loc2 < loc3) 
            {
                (loc4 = this._textFields[loc2]).htmlText = this._textStrs[loc2];
                ++loc2;
            }
            this._getBtn1.enabled = false;
            this._getBtn2.enabled = false;
            this._blessGetBtn.enabled = false;
            return;
        }

        /* internal  */weekVip(arg1: string): void
        {
            _titleTxt2.text = Language.getStringByParam(20588, Language.getString(20589)) + "：";
            this.updateAttri(arg1);
            return;
        }

        /* internal  */monthVip(arg1: string): void
        {
            _titleTxt2.text = Language.getStringByParam(20588, Language.getString(20590)) + "：";
            this.updateAttri(arg1);
            return;
        }

        /* internal  */halfYearVip(arg1: string): void
        {
            _titleTxt2.text = Language.getStringByParam(20588, Language.getString(20591)) + "：";
            this.updateAttri(arg1);
            return;
        }

        /* internal  */updateAttri(arg1: string): void
        {
            var loc3=null;
            var loc4=null;
            this._goldTxt.text = "1." + Language.getStringByParam(20580, VIPConfig.instance.getVIPInfo("EVIPCodeLoginReward")[arg1]) + "，" + Language.getStringByParam(20581, VIPConfig.instance.getVIPInfo("EVIPCodeDrugChangeNum")[arg1]);
            this._copperTxt.text = "2." + Language.getStringByParam(20582, VIPConfig.instance.getVIPInfo("EVIPCodeWeekendReward")[arg1]);
            var loc1=Cache.instance.vip.weekGiftItemCode;
            if (loc1 != 0) 
            {
                loc3 = new ItemData(loc1);
                loc4 = ColorConfig.instance.getItemColor(loc3.itemInfo.item.color).color;
                this._blessTxt.htmlText = "3.<font color=\'" + loc4 + "\'>" + loc3.itemInfo.item.name + "</font>";
            }
            if (!(this._vipInfo.rewards & 1) && VIPConfig.instance.getVIPInfo("EVIPCodeLoginReward")[arg1] > 0 || !(this._vipInfo.rewards & 4) && VIPConfig.instance.getVIPInfo("EVIPCodeDrugChangeNum")[arg1] > 0) 
            {
                this._getBtn1.enabled = true;
            }
            else 
            {
                this._getBtn1.enabled = false;
            }
            if (!(this._vipInfo.rewards & 2) && (ClockManager.instance.nowDate.day == 6 || ClockManager.instance.nowDate.day == 0)) 
            {
                this._getBtn2.enabled = true;
            }
            else 
            {
                this._getBtn2.enabled = false;
            }
            if (Cache.instance.vip.isGetWeekGift()) 
            {
                this._blessGetBtn.enabled = false;
            }
            else 
            {
                this._blessGetBtn.enabled = true;
            }
            var loc2=VIPConfig.instance.getVIPInfo("EVIPCodeShoes")[arg1];
            if (loc2 != -1) 
            {
                this._flyTxt.text = "4." + Language.getStringByParam(20584, loc2 - this._vipInfo.shoe);
            }
            else 
            {
                this._flyTxt.text = "4." + Language.getStringByParam(20584, Language.getString(20592));
            }
            return;
        }

        protected /* override */ initUI(): void
        {
            var loc1=0;
            var loc3=null;
            super.initUI();
            _titleTxt.text = Language.getString(20593);
            this._infoTxt = new Object /* flash.text.TextField */();
            this._infoTxt.autoSize = flash.text.TextFieldAutoSize.LEFT;
            this._infoTxt.textColor = GlobalStyle.color1Uint;
            this._infoTxt.multiline = true;
            this._infoTxt.wordWrap = true;
            this._infoTxt.width = width;
            this._infoTxt.height = 18;
            this._infoTxt.x = 5;
            this._infoTxt.y = _titleBg2.y + _titleBg2.height + 8;
            this._infoTxt.mouseEnabled = false;
            this._infoTxt.htmlText = HTMLUtil.addColor(Language.getString(20596), GlobalStyle.color1);
            addChild(this._infoTxt);
            var loc2=this._textFields.length;
            while (loc1 < loc2) 
            {
                loc3 = this._textFields[loc1];
                loc3.autoSize = flash.text.TextFieldAutoSize.LEFT;
                loc3.textColor = GlobalStyle.color1Uint;
                loc3.width = width;
                loc3.height = 18;
                loc3.htmlText = this._textStrs[loc1];
                loc3.x = 5;
                loc3.y = this._infoTxt.y + this._infoTxt.textHeight + 8 + loc1 * 25;
                loc3.mouseEnabled = false;
                addChild(loc3);
                ++loc1;
            }
            this._getBtn1 = new GButton();
            this._getBtn1.styleName = "Button";
            this._getBtn1.setSize(44, 20);
            this._getBtn1.label = Language.getString(20564);
            this._getBtn1.textField.filters = [FilterConst.glowFilter];
            this._getBtn1.addEventListener(flash.events.MouseEvent.CLICK, this.onGetBtn1ClickHandler);
            this._getBtn1.x = width - this._getBtn1.width - 5;
            this._getBtn1.y = this._goldTxt.y;
            addChild(this._getBtn1);
            this._getBtn2 = new GButton();
            this._getBtn2.styleName = "Button";
            this._getBtn2.setSize(44, 20);
            this._getBtn2.label = Language.getString(20564);
            this._getBtn2.textField.filters = [FilterConst.glowFilter];
            this._getBtn2.addEventListener(flash.events.MouseEvent.CLICK, this.onGetBtn2ClickHandler);
            this._getBtn2.x = width - this._getBtn2.width - 5;
            this._getBtn2.y = this._copperTxt.y;
            addChild(this._getBtn2);
            this._blessGetBtn = new GButton();
            this._blessGetBtn.styleName = "Button";
            this._blessGetBtn.setSize(44, 20);
            this._blessGetBtn.label = Language.getString(20564);
            this._blessGetBtn.textField.filters = [FilterConst.glowFilter];
            this._blessGetBtn.addEventListener(flash.events.MouseEvent.CLICK, this.onBlessGetBtnClickHandler);
            this._blessGetBtn.x = width - this._blessGetBtn.width - 5;
            this._blessGetBtn.y = this._blessTxt.y;
            addChild(this._blessGetBtn);
            return;
        }

        /* internal */ /* var */_infoTxt: Object /* flash.text.TextField */;

        /* internal */ /* var */_goldTxt: Object /* flash.text.TextField */;

        /* internal */ /* var */_copperTxt: Object /* flash.text.TextField */;

        /* internal */ /* var */_blessTxt: Object /* flash.text.TextField */;

        /* internal */ /* var */_flyTxt: Object /* flash.text.TextField */;

        /* internal */ /* var */_getBtn1: GButton;

        /* internal */ /* var */_getBtn2: GButton;

        /* internal */ /* var */_blessGetBtn: GButton;

        /* internal */ /* var */_vipInfo: SVIPInfo;

        /* internal */ /* var */_isStart: Boolean;

        /* internal */ /* var */_textFields: Array<any>;

        /* internal */ /* var */_textStrs: Array<any>;

        /* internal */ /* var */_attriName: string;
    }
